package common;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.HashMap;
import java.util.logging.Filter;
import java.util.logging.LogRecord;

public class SetChar extends HttpServlet implements Filter {
	private FilterConfig filterConfig;

	// Handle the passed-in FilterConfig
	public void init(FilterConfig filterConfig) throws ServletException {
		this.filterConfig = filterConfig;
	}

	// Process the request/response pair
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain filterChain) {
		
		  ((HttpServletResponse) response).setHeader("Pragma", "No-cache");
		  ((HttpServletResponse) response).setHeader("Cache-Control", "no-cache");
		  ((HttpServletResponse) response).setHeader("Expires", "0");

         try {
			//request.setCharacterEncoding("UTF-8");
			response.setCharacterEncoding("UTF-8");
			request.setCharacterEncoding("UTF-8");
			filterChain.doFilter(request, response);
			
		} catch (ServletException sx) {
			filterConfig.getServletContext().log(sx.getMessage());
		} catch (IOException iox) {
			filterConfig.getServletContext().log(iox.getMessage());
		}
	}

	// Clean up resources
	public void destroy() {
	}

	@Override
	public boolean isLoggable(LogRecord record) {
		return false;
	}
}
